<template>
  <div class="admin_index">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>基本信息</span>
        <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
      </div>
      <div class="user_info">
        <div class="info_item">
          <div class="info_left">用户名：</div>
          <div class="info_value">test</div>
        </div>
        <div class="info_item">
          <div class="info_left">姓名:</div>
          <div class="info_value">test</div>
          <el-button type="default" size="mini" class="change">修改</el-button>
        </div>
        <div class="info_item">
          <div class="info_left">手机号码：</div>
          <div class="info_value">test</div>
          <el-button type="default" size="mini" class="change">修改</el-button>
        </div>
        <div class="info_item">
          <div class="info_left">电子邮箱：</div>
          <div class="info_value">test</div>
          <el-button type="default" size="mini" class="change">修改</el-button>
        </div>
        <div class="info_item">
          <div class="info_left">我的企业：</div>
          <div class="info_value">test</div>
          <el-button type="default" size="mini" class="change">申请加入企业</el-button>
          <el-button type="default" size="mini" class="change">申请企业认证</el-button>
        </div>
        <div class="info_item upload">
          <div class="info_left">个人头像：</div>
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <div class="info_value tip">支持 JPG、JPEG、PNG、BMP 格式，图片小于1M</div>
          <!-- <el-button type="default" size="mini" class="change">修改</el-button> -->
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      imageUrl: ""
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    }
  }
};
</script>

<style lang="less" scoped>
.admin_index {
  // min-width: 1280px;
  padding: 20px;
}
.user_info {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-left: 20px;
  .info_item {
    min-width: 400px;
    display: flex;
    align-items: baseline;
    padding: 10px 0;
    .tip {
      color: #999;
      font-size: 14px;
    }
    .info_left {
      font-size: 16px;
      margin-right: 10px;
    }
    .change {
      transform: translateY(-2px);
      margin-left: 20px;
    }
  }
  .upload{
    align-items: center;
  }
}
/deep/.avatar-uploader .el-upload {
  border: 1px dashed #ccc;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  margin-right: 10px;
}
/deep/.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
/deep/.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>